package com.example.ujsfish.activity;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;

import com.example.ujsfish.R;

public class CruiseActivity extends AppCompatActivity {

    CruiseFragment fragment = new CruiseFragment();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.cruise_activity);
        //设置菜单栏返回按钮
        setBackButton();

        //获取传入的类型数据
        Intent intent = getIntent();
        String type = intent.getStringExtra("type");

        //使用Bundle向fragment传递type
        Bundle bundle = new Bundle();
        bundle.putString("type",type);
        fragment.setArguments(bundle);


        //动态添加Fragment
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.cruiseFrame,fragment);
        fragmentTransaction.commit();


    }

    private void setBackButton() {
        ActionBar actionBar = this.getSupportActionBar();
        actionBar.setTitle("巡航设置");
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if(item.getItemId() == android.R.id.home)
        {
            finish();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}